package com.kgc.novel.controller;


import com.kgc.novel.common.Res;
import com.kgc.novel.domain.entity.BookUser;
import com.kgc.novel.domain.param.BookUserParam;
import com.kgc.novel.service.user.BookUserService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/user")
@Api(tags = "用户接口")
public class BookUserController {

    @Resource
    private BookUserService userService;


    @PostMapping("/search")
    public Res listUserPage(@RequestBody BookUserParam param) {

        return userService.getUserByPage(param);
    }

    @GetMapping("/get/{userId}")
    public Res getUser(
            @PathVariable String userId) {


        BookUser userEntity = userService.getById(userId);
        return Res.returnData(userEntity);
    }


    @PostMapping("/saveOrUpdate")
    public Res saveOrUpdateUser(@RequestBody BookUser userModel) {
        boolean retVal = userService.saveOrUpdate(userModel);
        if(retVal) {
            return Res.returnMsg("保存用户信息成功");
        }
        else {
            return Res.returnErrMsg("保存用户信息失败！");
        }
    }



//    @ApiOperation(value = "根据用户ID删除用户信息",notes = "根据用户ID删除用户信息的方法")
//    @ApiImplicitParam(paramType = "query", name = "userId", value = "主键ID", required = true, dataType = "String")
//    ApiResult deleteUserById(@RequestParam(value = "userId") String userId){
//        boolean retVal = userService.removeById(userId);
//        if(retVal) {
//            return ApiResult.success(null,"删除用户信息成功");
//        }
//        else {
//            return ApiResult.fail("删除用户信息失败！");
//        }
//    }

}
